<?php
	require_once "View\FileUploadView.php";
	require_once "Model\FileUploadHandler.php";
	
	class FileUploadReturnValue {
		public $html = "";
		public $feedback = "";
	}
	
	class FileUploadController {
			
		//Privata variabler
		private $fh;
		private $fv;
		
		//Konstruktor som tar emot objekt
		public function __construct(){
			$this->fh = new FileUploadHandler();
			$this->fv = new FileUploadView($this->fh);
		}
		
		public function DoControll($isLoggedIn){
			$ret = new FileUploadReturnValue();
			
			//Kollar om användaren är inloggad...
			if ($isLoggedIn) {
				
				//...och vill ladda upp en fil.
				if($this->fv->TriedToUpload()){
				
					//Hämtar, kollar och sparar filen.
					$ret->feedback = $this->fh->SaveFile($this->fv->GetUpload());
					
					//Lägger in ev felmeddelanden
					$ret->html = $this->fv->DoFeedback($ret->feedback);
				}
				//Lägger ihop html
				$ret->html .= $this->fv->DoFileList();
				$ret->html .= $this->fv->DoUploadform();
			} 
			//...eller utloggad
			else {
				$ret->html = $this->fv->DoFileList();
			}
			return $ret;
		}
	}
?>